import javax.servlet.http.HttpUtils

def req_infos = [["Request method", "method"],
                 ["Request URI", "requestURI"],
                 ["Request protocol", "protocol"],
                 ["Servlet path", "servletPath"],
                 ["Path info", "pathInfo"],
                 ["Path translated", "pathTranslated"],
                 ["Query string", "queryString"],
                 ["Content length", "contentLength"],
                 ["Content type", "contentType"],
                 ["Server name", "serverName"],
                 ["Server port", "serverPort"],
                 ["Remote user", "remoteUser"],
                 ["Remote address", "remoteAddr"],
                 ["Remote host", "remoteHost"],
                 ["Authorization scheme", "authType"]
				]

html.html {
	head {
		title "Groovlet Snoop Page"
	}
	body {
		h1 "Groovlet Snoop Page"

		h2 "Request information"
		table {
			tr{
				th align:"right", "Requested URL:"
				td HttpUtils.getRequestURL(request)
			}
			req_infos.each {req->
				tr {
				th align:"right", "${req[0]}:"
				td request."${req[1]}"
				}
			}
		}

		if(headers.size()){
			h2 "Request headers"
			table {
				tr {
					th align:"right", "Header:"
					th align:"left", "Value:"
				}
				headers.each { h ->
				tr {
					td align:"right", noWrap:"true", h.key+":"
					td h.value
				}
				}
			}
		}

		if(params.size()){
			h2 "Request parameters"
			table {
				tr {
					th align:"right", "Parameter:"
					th align:"left", "Value(s):"
				}
				params.each { p ->
				tr {
					td align:"right", noWrap:"true", p.key+":"
					td p.value.toString()
				}
				}
			}
		}

	}
}
